/******************************************************************************
 *  _____     _____
 *  \  __\    \  __\
 *   \ \_\\    \ \_\\
 *    \  __\SS  \  __\roject
 *     \_\       \_\
 *
 * Mateusz Maciąg, Rafał Urbański
 * Komputerowe Systemy Sterowania
 *****************************************************************************/

#ifndef RSTCONTROLLERDESIGNER_H
#define RSTCONTROLLERDESIGNER_H

#include "SimInterface/IConfigurable.h"
#include "ControllerDesigner.h"

#include "SimInterface/ISimulator.h"
#include "AdaptDesigners/AdaptiveAlgorithmDesignerBase.h"

#include <QFrame>


namespace Ui {
class RSTControllerDesigner;
}

class RSTControllerDesigner : public ControllerDesigner
{
    Q_OBJECT

public:
    explicit RSTControllerDesigner(QWidget *parent = 0);
    ~RSTControllerDesigner();

    /**
        Dołącza regulator do konfiguracji.
    */
    void attachController(RafMat::SimInterface::IConfigurableSPtr ctrl);

    /**
        Zapisuje zmiany w konfiguracji.
    */
    void applySettings();

private slots:
    void on_btnAdptSettings_clicked();
    void on_refreshTimer_timeot();

    void on_cbAdptType_currentIndexChanged(int index);

private:
    void initializeSettings();

    /** Aktualizuje wielomiany w widoku ustawień kontrolera */
    void updateRSTState();

    RafMat::SimInterface::ISimulator::AdptType getAlgorithmType() const;

    void changeAlgorithmConfiguration(RafMat::SimInterface::ISimulator::AdptType adptType);
    void changeAlgorithmDesigner(RafMat::SimInterface::ISimulator::AdptType adptType);

    int findAlgIndex(RafMat::SimInterface::ISimulator::AdptType adptType);
    RafMat::SimInterface::ISimulator::AdptType indexToAlgType(int idx);

    bool forceViewUpdate;
    //RafMat::SimInterface::ISimulator::AdptType currentAdptType;

    AdaptiveAlgorithmDesignerBase      *m_currentAdptDesigner;

    Ui::RSTControllerDesigner *ui;
    QTimer* m_refreshTimer;

    RafMat::SimInterface::IConfigurableSPtr m_controllerConf;
};

#endif // RSTCONTROLLERDESIGNER_H

